package <%=basePackage%>.dao;

import java.util.Date;
import java.util.List;

import javax.inject.Inject;

import org.junit.Assert;
import org.junit.Test;
import org.springframework.transaction.annotation.Transactional;

import com.tianxian.SpringTest;
import <%=className%>;

public class <%=simpleClassName%>DaoTest extends SpringTest {
    @Inject
    <%=simpleClassName%>Dao <%=entity%>Dao;

    @Test
    public void testSave() {
        <%=simpleClassName%> <%=entity%> = mock<%=simpleClassName%>();
        this.<%=entity%>Dao.save(<%=entity%>);

        Assert.assertNotNull(<%=entity%>.getId());
    }

    @Test
    public void testUpdate() {
        <%=simpleClassName%> <%=entity%> = mock<%=simpleClassName%>();
        this.<%=entity%>Dao.save(<%=entity%>);
        <%=entity%>.setLastUpdateTime(new Date());
        this.<%=entity%>Dao.update(<%=entity%>);
        Assert.assertNotNull(<%=entity%>.getId());
    }

    @Test
    public void testFindOne() {
        <%=simpleClassName%> <%=entity%> = mock<%=simpleClassName%>();
        this.<%=entity%>Dao.save(<%=entity%>);

        <%=entity%> = this.<%=entity%>Dao.findOne(<%=entity%>.getId());
        Assert.assertNotNull(<%=entity%>);
    }

    @Test
    public void testFindAll() {
        <%=simpleClassName%> <%=entity%> = mock<%=simpleClassName%>();
        this.<%=entity%>Dao.save(<%=entity%>);

        List<<%=simpleClassName%>> list = this.<%=entity%>Dao.findAll(0, 20);
        Assert.assertFalse(list.isEmpty());
    }
    
    <%=simpleClassName%> mock<%=simpleClassName%>(){
        <%=simpleClassName%> <%=entity%> = new <%=simpleClassName%>();
        <%for(field : fields){%><%if(!field.generated)%>
        <%=entity%>.<%=field.setter%>(+);		
        <%}%><%}%>
        return <%=entity%>;
    }

}
